/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.jobmesmanage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.modules.jobmesmanage.service.SchoStutypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.SchoStuwork;
import com.lczyfz.campusinfo.modules.jobmesmanage.service.SchoStuworkService;
import com.lczyfz.campusinfo.modules.jobmesmanage.entity.SchoStutype;
import java.util.List;

/**
 * 勤工详情Controller
 * @author zms
 * @version 2018-03-23
 */
@Controller
@RequestMapping(value = "${adminPath}/jobmesmanage/schoStuwork")
public class SchoStuworkController extends BaseController {

	@Autowired
	private SchoStuworkService schoStuworkService;
	@Autowired
	private SchoStutypeService schoStutypeService;
	@ModelAttribute
	public SchoStuwork get(@RequestParam(required=false) String id) {
		SchoStuwork entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = schoStuworkService.get(id);
		}
		if (entity == null){
			entity = new SchoStuwork();
		}
		return entity;
	}
	
	@RequiresPermissions("jobmesmanage:schoStuwork:view")
	@RequestMapping(value = {"list", ""})
	public String list(SchoStuwork schoStuwork, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<SchoStuwork> page = schoStuworkService.findPage(new Page<SchoStuwork>(request, response), schoStuwork);
		List<SchoStuwork> schoStuworks = schoStuworkService.findList(schoStuwork);
		model.addAttribute("schoStuworks",schoStuworks);
		model.addAttribute("page", page);
		return "modules/campusinfostu/schoStuworkList";
	}

	@RequiresPermissions("jobmesmanage:schoStuwork:view")
	@RequestMapping(value = "form")
	public String form(SchoStuwork schoStuwork, Model model) {
		SchoStutype schoStutype = new SchoStutype();
		List<SchoStutype> schoStutypes = schoStutypeService.findList(schoStutype);
		model.addAttribute("schoStutypes", schoStutypes);
		model.addAttribute("schoStuwork", schoStuwork);
		return "modules/campusinfostu/schoStuworkForm";
	}

	@RequiresPermissions("jobmesmanage:schoStuwork:edit")
	@RequestMapping(value = "save")
	public String save(SchoStuwork schoStuwork, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, schoStuwork)){
			return form(schoStuwork, model);
		}
		schoStuworkService.save(schoStuwork);
		addMessage(redirectAttributes, "保存勤工详情成功");
		return "redirect:"+Global.getAdminPath()+"/jobmesmanage/schoStuwork/?repage";
	}
	
	@RequiresPermissions("jobmesmanage:schoStuwork:edit")
	@RequestMapping(value = "delete")
	public String delete(SchoStuwork schoStuwork, RedirectAttributes redirectAttributes) {
		schoStuworkService.delete(schoStuwork);
		addMessage(redirectAttributes, "删除勤工详情成功");
		return "redirect:"+Global.getAdminPath()+"/jobmesmanage/schoStuwork/?repage";
	}

}